package com.howard.modules.user.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Service;
import com.howard.modules.user.User;
import com.howard.modules.user.dao.UserDao;
import com.howard.modules.base.dao.impl.AppBaseDaoImpl;

@Service
public class UserDaoImpl extends AppBaseDaoImpl<User> implements UserDao {
	@Override
	public Class<User> getDomainClass() {
		return User.class;
	}

	@Override
	public User queryUser(User user) {
		String sql = " from "+getDomainClass().getName()+" t where t.userName=:loginName and t.password=:password";
		HashMap<String,String> m = new HashMap<String,String>();
		m.put("loginName",user.getUsername());
		m.put("password", user.getPassword());
		
		List<User> list = getList(sql, m, null);
		if(null!=list && list.size()>0){
			return (User)list.get(0);
		}
		return null;
	}

	@Override
	public User queryUserByName(String name) {
		String sql = " from "+getDomainClass().getName()+" t where t.userName=:loginName ";
		HashMap<String,String> m = new HashMap<String,String>();
		m.put("loginName",name);
		
		List<User> list = getList(sql, m, null);
		if(null!=list && list.size()>0){
			return (User)list.get(0);
		}
		return null;
	}

	
}
